home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWViews / FWPictSv.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  7.5 KB  |  270 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPictSv.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWPICTSV_H
  13. #include "FWPictSv.h"
  14. #endif
  15.  
  16. #ifndef FWCONTXT_H
  17. #include "FWContxt.h"
  18. #endif
  19.  
  20. #ifndef FWPICSHP_H
  21. #include "FWPicShp.h"
  22. #endif
  23.  
  24. #ifndef FWCFMRES_H
  25. #include "FWCFMRes.h"
  26. #endif
  27.  
  28. #ifndef FWRECSHP_H
  29. #include "FWRecShp.h"
  30. #endif
  31.  
  32. #ifndef FWTXTBOX_H
  33. #include "FWTxtBox.h"
  34. #endif
  35.  
  36. //========================================================================================
  37. // File scope definitions
  38. //========================================================================================
  39.  
  40. #ifdef FW_BUILD_MAC
  41. #pragma segment fwgadgts
  42. #endif
  43.  
  44. //========================================================================================
  45. // CLASS FW_CPictSView
  46. //========================================================================================
  47.  
  48. //FW_DEFINE_CLASS_M1(FW_CPictSView, FW_CSuperView)
  49. FW_DEFINE_AUTO(FW_CPictSView)
  50.  
  51. // This class is archivable, but we provide the archiving implementation in a separate
  52. // translation unit in order to enable deadstripping of the archiving-related code
  53. // in parts that do not use archiving with this class.
  54.  
  55. //----------------------------------------------------------------------------------------
  56. // FW_CPictSView::FW_CPictSView
  57. //----------------------------------------------------------------------------------------
  58.  
  59. FW_CPictSView::FW_CPictSView (Environment *ev, 
  60.                             FW_CSuperView* container, 
  61.                             const FW_CRect& bounds,
  62.                             ODID viewID,
  63.                             FW_CPicture& picture,
  64.                             FW_EScrollingDirection scrollDir) :
  65.     FW_CSuperView(ev, container, bounds, viewID, FW_kZeroPoint, scrollDir),
  66.     fPicture(picture),
  67.     fPictID(0),
  68.     fPictNotFound(false)
  69. {
  70.     // Adjust the view extent to the size of the picture
  71.     FW_CRect rect;
  72.     picture.GetPictBounds(rect);
  73.     SetExtent(ev, rect.Size());
  74.  
  75.     // Overrides FW_CSuperView default bindings to keep fixed bounds
  76.     SetBindings(ev, FW_kFixedBounds);
  77. //    SetResizeForceRedraw(ev, true);
  78.  
  79.     FW_END_CONSTRUCTOR
  80. }
  81.  
  82. //----------------------------------------------------------------------------------------
  83. // FW_CPictSView::FW_CPictSView
  84. //----------------------------------------------------------------------------------------
  85.  
  86. FW_CPictSView::FW_CPictSView (Environment *ev, 
  87.                             FW_CSuperView* container, 
  88.                             const FW_CRect& bounds,
  89.                             ODID viewID,
  90.                             FW_ResourceID pictID,
  91.                             const FW_CPoint& extent,
  92.                             FW_EScrollingDirection scrollDir) :
  93.     FW_CSuperView(ev, container, bounds, viewID, FW_kZeroPoint, scrollDir),
  94.     fPictID(pictID),
  95.     fPictNotFound(false)
  96. {
  97.     Initialize(ev, extent);
  98.  
  99.     // Overrides FW_CSuperView default bindings to keep fixed bounds
  100.     SetBindings(ev, FW_kFixedBounds);
  101. //    SetResizeForceRedraw(ev, true);
  102.     
  103.     FW_END_CONSTRUCTOR
  104. }
  105.  
  106. //----------------------------------------------------------------------------------------
  107. // FW_CPictSView::FW_CPictSView
  108. //----------------------------------------------------------------------------------------
  109.  
  110. FW_CPictSView::FW_CPictSView(Environment* ev) :
  111.     FW_CSuperView(ev),
  112.     fPictID(0),
  113.     fPictNotFound(false)
  114. {
  115.     FW_END_CONSTRUCTOR
  116. }
  117.  
  118. //----------------------------------------------------------------------------------------
  119. // FW_CPictSView::~FW_CPictSView
  120. //----------------------------------------------------------------------------------------
  121.  
  122. FW_CPictSView::~FW_CPictSView()
  123. {
  124.     FW_START_DESTRUCTOR
  125. }
  126.  
  127. //----------------------------------------------------------------------------------------
  128. // FW_CPictSView::Initialize
  129. //----------------------------------------------------------------------------------------
  130.  
  131. void FW_CPictSView::Initialize(Environment* ev, const FW_CPoint& extent) 
  132. {
  133.     FW_TRY
  134.     {
  135.         // Load the picture from the part shared library
  136.         FW_PSharedLibraryResourceFile resFile(ev);
  137.         fPicture = FW_CPicture(resFile, fPictID);
  138.  
  139.         // By default we adjust the view extent to the size of the picture    
  140.         if (extent == FW_kZeroPoint)
  141.         {
  142.             FW_CRect rect;
  143.             fPicture.GetPictBounds(rect);
  144.             SetExtent(ev, rect.Size());
  145.         }
  146.         else
  147.         {
  148.             SetExtent(ev, extent);
  149.         }
  150.     }
  151.     FW_CATCH_BEGIN
  152.     FW_CATCH_REFERENCE(FW_XException, except)
  153.     {
  154.         fPictNotFound = true;
  155.         SetExtent(ev, GetBounds(ev).Size());
  156.     }
  157.     FW_CATCH_END
  158. }
  159.  
  160. //----------------------------------------------------------------------------------------
  161. // FW_CPictSView::DrawPictNotFound
  162. //----------------------------------------------------------------------------------------
  163.  
  164. void FW_CPictSView::DrawPictNotFound(Environment* ev, FW_CViewContext& vc, FW_Boolean usePictID)
  165. {
  166.     // Draw a pink rectangle
  167.     FW_CRect viewRect(FW_kZeroPoint, GetExtent(ev));
  168.     FW_CRectShape::RenderRect(vc, viewRect, FW_kFill, FW_CColor(255, 204, 204), 
  169.                             FW_CStyle(FW_kFixedPos1, FW_kGrayPat)); 
  170.  
  171.     FW_CString text;
  172.     if (usePictID)
  173.     {
  174.         // Write the classID in the middle
  175.         FW_CString idstr;
  176.         idstr.ReplaceAllAsSignedDecimalInteger(fPictID);
  177.         text += "PICT ID ";
  178.         text += idstr;
  179.         text += " not found!";
  180.     }
  181.     else
  182.         text += "Picture not found!";
  183.         
  184.     FW_CTextBoxShape::RenderTextBox(vc, text, viewRect, 
  185.                     FW_CFont(FW_GetDefaultFontName(), FW_kBold, FW_IntToFixed(10)), 0);
  186. }
  187.  
  188. //----------------------------------------------------------------------------------------
  189. // FW_CPictSView::Draw
  190. //----------------------------------------------------------------------------------------
  191.  
  192. void FW_CPictSView::Draw(Environment* ev, ODFacet* facet, ODShape* invalidShape)
  193. {
  194.     FW_CViewContext    vc(ev, this, facet, invalidShape);
  195.     
  196.     if (fPictNotFound)
  197.     {
  198.         DrawPictNotFound(ev, vc, true);
  199.     }
  200.     else
  201.     {
  202.         // Erase with white first 
  203.         FW_CRect invalidRect;
  204.         vc.GetClipRect(invalidRect);
  205.         FW_CRectShape::RenderRect(vc, invalidRect, FW_kFill, FW_kWhiteEraseInk);
  206.  
  207.         FW_CRect rect(FW_kZeroPoint, GetExtent(ev));
  208.         FW_CPictureShape::RenderPicture(vc, fPicture, rect);
  209.     }
  210. }
  211.  
  212. //----------------------------------------------------------------------------------------
  213. // FW_CPictSView::DrawAnotherPicture
  214. //----------------------------------------------------------------------------------------
  215.  
  216. void FW_CPictSView::DrawAnotherPicture(Environment* ev, ODFacet* facet, ODShape* invalidShape,
  217.                                     FW_CPicture& picture, FW_Boolean scale)
  218. {
  219.     // This is the same as Draw, but using another picture
  220.  
  221.     FW_CViewContext    vc(ev, this, facet, invalidShape);
  222.     
  223.     // Erase with white first 
  224.     FW_CRect invalidRect;
  225.     vc.GetClipRect(invalidRect);
  226.     FW_CRectShape::RenderRect(vc, invalidRect, FW_kFill, FW_kWhiteEraseInk);
  227.  
  228.     if (picture)
  229.     {
  230.         FW_CRect rect;
  231.         if (scale)
  232.             rect = FW_CRect(FW_kZeroPoint, GetExtent(ev));
  233.         else
  234.             picture.GetPictBounds(rect);
  235.             
  236.         FW_CPictureShape::RenderPicture(vc, picture, rect);
  237.     }
  238.     else
  239.     {
  240. #ifdef FW_DEBUG
  241.         DrawPictNotFound(ev, vc, false);
  242. #endif
  243.     }
  244. }
  245.  
  246. //----------------------------------------------------------------------------------------
  247. //    FW_CPictSView::Flatten
  248. //----------------------------------------------------------------------------------------
  249.  
  250. void FW_CPictSView::Flatten(Environment* ev, FW_CWritableStream& stream) const
  251. {
  252.     FW_CSuperView::Flatten(ev, stream);
  253.     
  254.     stream << fPictID;         
  255. }
  256.  
  257. //----------------------------------------------------------------------------------------
  258. //    FW_CPictSView::InitializeFromStream
  259. //----------------------------------------------------------------------------------------
  260.  
  261. void FW_CPictSView::InitializeFromStream(Environment* ev, FW_CReadableStream& stream)
  262. {
  263.     FW_CSuperView::InitializeFromStream(ev, stream);
  264.  
  265.     stream >> fPictID;    
  266.     
  267.     Initialize(ev, FW_kZeroPoint);
  268. }
  269.  
  270.